package rebellion.meso.builder;

import rebellion.Constants;
import rebellion.CoverageCounter;
import rebellion.util.RebellionEnvironment;
import rebellion.util.RebellionScenarioBuilder;
import repast.simphony.context.space.continuous.ContinuousSpaceFactoryFinder;
import repast.simphony.context.space.grid.GridFactoryFinder;
import repast.simphony.engine.environment.RunEnvironment;
import repast.simphony.parameter.Parameters;
import repast.simphony.space.continuous.ContinuousSpace;
import repast.simphony.space.continuous.RandomCartesianAdder;
import repast.simphony.space.grid.GridBuilderParameters;
import repast.simphony.space.grid.RandomGridAdder;

/**
 * Scenario builder for Cop class micro level test scenarios.
 * 
 * @author İbrahim Çakırlar
 * 
 */
public class CoverageCounterWithCopScenarioBuilder extends
		RebellionScenarioBuilder {

	/*
	 * (non-Javadoc)
	 * 
	 * @see ratkit.repast.RepastScenarioBuilder#createAgents()
	 */
	@SuppressWarnings("unchecked")
	@Override
	protected void createAgents() {
		// create a new Coverage Counter agent for test...
		CoverageCounter counterAgent = RebellionEnvironment.getInstance()
				.createCovarageCounter("counter1");
		getContext().add(counterAgent);
		// get parameter values...
		Parameters p = RunEnvironment.getInstance().getParameters();
		int visNeighbors = (Integer) p.getValue("visNeighbors");
		double govLegitimacy = (Double) p.getValue("govLegitimacy");
		int maxJailTerm = (Integer) p.getValue("maxJailTerm");
		getContext().add(
				RebellionEnvironment.getInstance().createPerson("person1",
						getGrid(), visNeighbors, maxJailTerm, govLegitimacy));
		getContext().add(
				RebellionEnvironment.getInstance().createCop("cop1", getGrid(),
						visNeighbors));
	}

	@SuppressWarnings({ "unused", "unchecked" })
	@Override
	protected void createGridAndContinuousSpace() {
		getContext().setId(Constants.CONTEXT_ID);
		Parameters p = RunEnvironment.getInstance().getParameters();
		int visNeighbors = (Integer) p.getValue("visNeighbors");
		// create space
		final ContinuousSpace<Object> space = ContinuousSpaceFactoryFinder
				.createContinuousSpaceFactory(null)
				.createContinuousSpace(
						Constants.SPACE_ID,
						getContext(),
						new RandomCartesianAdder<Object>(),
						new repast.simphony.space.continuous.WrapAroundBorders(),
						visNeighbors, visNeighbors);

		// create grid
		setGrid(GridFactoryFinder.createGridFactory(null).createGrid(
				Constants.GRID_ID,
				getContext(),
				new GridBuilderParameters<Object>(
						new repast.simphony.space.grid.WrapAroundBorders(),
						new RandomGridAdder<Object>(), false, visNeighbors,
						visNeighbors)));
	}

}
